/*
 * Copyright (C) 2011 Caldia Apps.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.caldia.android.sample.DisplayMetrics;

import android.app.Activity;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.Display;
import android.widget.EditText;
import android.widget.TableRow;
import android.widget.TextView;

public class EntryActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        // ディスプレイ情報取得用
        final Display display = getWindowManager().getDefaultDisplay();

        // ディスプレイ情報の保存先
        final DisplayMetrics metrics = new DisplayMetrics();

        // ディスプレイ情報取得
        display.getMetrics(metrics);

        setValues(R.id.tableRow1, "xdpi", metrics.xdpi);
        setValues(R.id.tableRow2, "ydpi", metrics.ydpi);
        setValues(R.id.tableRow3, "widthPixels", metrics.widthPixels);
        setValues(R.id.tableRow4, "heightPixels", metrics.heightPixels);
        setValues(R.id.tableRow5, "density", metrics.density);
        setValues(R.id.tableRow6, "densityDpi", metrics.densityDpi);
        setValues(R.id.tableRow7, "scaledDensity", metrics.scaledDensity);

        setValues(R.id.tableRow8, "getWidth", display.getWidth());
        setValues(R.id.tableRow9, "getHeight", display.getHeight());
        setValues(R.id.tableRow10, "getDisplayId", display.getDisplayId());
        setValues(R.id.tableRow11, "getOrientation", display.getOrientation());
        setValues(R.id.tableRow12, "getPixelFormat", display.getPixelFormat());
        setValues(R.id.tableRow13, "getRefreshRate", display.getRefreshRate());

    }


    /**
     * タイトルと値をViewに設定する
     * @param rowResId	TableRow のID
     * @param title	タイトル
     * @param value	値
     */
    private void setValues(final int rowResId, final String title, final Object value) {

    	// 行
    	final TableRow vRow = (TableRow)findViewById(rowResId);

    	// タイトル
    	((TextView)vRow.findViewById(R.id.textView)).setText(title);

    	// 値
    	((EditText)vRow.findViewById(R.id.editText)).setText(String.valueOf(value));


    }
}